const fs = require('fs');

function base64Encode(content) {
  const buf = Buffer.from(content);
  const base64 = buf.toString('base64');
  return base64;
}

function base64Decode(str) {
  const buf = Buffer.from(str, 'base64');
  return buf;
}

// Test
fs.readFile('../static/kail-1.png', (err, data) => {
  if (err) {
    console.log(err);
    return;
  }

  const imgBase64 = base64Encode(data);
  console.log('imgBase64: ', imgBase64);
  const img = base64Decode(imgBase64);
  fs.writeFileSync('kail.png', img);
});
